<?php $__env->startSection('css'); ?>
    <style>
        .thumb {
            max-height: 60px;
        }
    </style>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <div class="admin-content">

        <div class="am-cf am-padding">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">广告列表</strong> /
                <small>Ad List</small>
            </div>
        </div><br/>
        <?php if(session('ads')): ?>
            <div class="am-g">
                <div class="am-u-md-12">
                    <div class="am-alert am-alert-success">
                        <?php echo e(session('ads')); ?>

                    </div>
                </div>
            </div>
        <?php endif; ?>

        <div class="am-g">
            <div class="am-u-sm-12 am-u-md-6">
                <div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                        <a type="button" class="am-btn am-btn-default" href="<?php echo e(route('ads.ad.create')); ?>">
                            <span class="am-icon-plus"></span> 新增
                        </a>

                        <button type="button" class="am-btn am-btn-default" id="destroy_checked">
                            <span class="am-icon-trash-o"></span> 删除
                        </button>
                    </div>
                </div>
            </div>
            <div class="am-u-sm-12 am-u-md-3">
                <div class="am-form-group">
                    <select data-am-selected="{btnWidth: '80%',  btnStyle: 'secondary', btnSize: 'sm', maxHeight: 360, searchBox: 1}" name="category_id" id="change_category" style="display: none;">
                        <option value="-1" <?php if(Request::input('category_id')=='-1'): ?> selected <?php endif; ?>>所有分类</option>
                        <option value="1" <?php if(Request::input('category_id')=='1'): ?> selected <?php endif; ?>>
                            首页焦点图 大图轮播
                        </option>
                        <option value="2" <?php if(Request::input('category_id')=='2'): ?> selected <?php endif; ?>>
                           首页banner 3广告
                        </option>
                    </select>

                </div>
            </div>

        </div>

        <div class="am-g">
            <div class="am-u-sm-12">
                <form class="am-form" id="form">
                    <table class="am-table am-table-striped am-table-hover table-main">
                        <thead>
                        <tr>
                            <th class="table-check"><input type="checkbox" id="checked"></th>
                            <th class="table-id">编号</th>
                            <th>缩略图</th>
                            <th class="table-title">标题</th>
                            <th class="table-category">所属栏目</th>
                            <th class="table-desc">描述信息</th>
                            <th class="table-sort-order am-hide-sm-only" style="width:10%">排序</th>
                            <th class="table-date am-hide-sm-only">发布日期</th>
                            <th class="table-set">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach($ads as $ad): ?>
                        <tr data-id="<?php echo e($ad->id); ?>">
                            <td><input type="checkbox" value="<?php echo e($ad->id); ?>" class="checked_id" name="checked_id[]"></td>
                            <td><?php echo e($ad->id); ?></td>
                            <td class="ad_thumb">
                                <img src="<?php echo e($ad->thumb); ?>" alt="" class="thumb">                                </td>
                            <td>
                                <a href="<?php echo e($ad->url); ?>" target="_blank"><?php echo e($ad->title); ?></a>
                            </td>

                            <td><?php echo e($ad->category->name); ?></td>

                            <td><?php echo e($ad->desc1); ?></td>

                            <td class="am-hide-sm-only">
                                <input type="text" name="sort_order" class="am-input-sm" value="<?php echo e($ad->sort_order); ?>">
                            </td>

                            <td class="am-hide-sm-only">
                                <?php echo e($ad->created_at); ?>

                            </td>

                            <td>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a class="am-btn am-btn-default am-btn-xs am-text-secondary" href="<?php echo e(route('ads.ad.edit',[$ad->id])); ?>">
                                            <span class="am-icon-pencil-square-o"></span> 编辑
                                        </a>

                                        <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" href="<?php echo e(route('ads.ad.destroy',[$ad->id])); ?>"
                                           data-method="delete" data-token="<?php echo e(csrf_token()); ?>" data-confirm="确定删除吗？">
                                            <span class="am-icon-trash-o"></span> 删除
                                        </a>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                        </tbody>
                    </table>

                    <div class="am-cf" style="float: right">

                        <?php echo $ads->appends(Request::all())->links(); ?>


                    </div>
                    <hr />
                    <p>共<?php echo e($ads->total()); ?>条记录</p>
                    <hr>
                </form>
            </div>

        </div>

    </div>
    <?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
    <script type="text/javascript">
        $(function(){

            //全选
            $('#checked').click(function(){
                $('.checked_id').prop('checked',this.checked);
            });

            //多选删除
            $('#destroy_checked').click(function(){
                var length=$('.checked_id:checked').length;
                if (length == 0) {
                    alert("您必须至少选中一条!");
                    return false;
                }

//                关键是获得要删除的ids数组
                var ids='';
                $('.checked_id:checked').each(function(){
                    ids+=$(this).val()+' ';
                })
                console.log(ids);

                //通过ajax发送ads 执行多选删除
                $.ajax({
                    url:'/ads/ad/destroy_checked',
                    data:{'ids':ids},
                    type:'delete',
                    success:function(){
                        location.href = location.href+'?'+Math.random();
                    }

                })
            })

            //切换栏目
            $('.am-selected-list').children().click(function(){
                $category_id=$(this).attr('data-value');
                /*if($category_id=='-1'){
                    return false;
                }*/
                var url="<?php echo e(route('ads.ad.index')); ?>?category_id="+$category_id;
                location.href=url;
            })


            //排序
            $("input[name='sort_order']").change(function(){
                var data={
                    sort_order:$(this).val(),
                    id:$(this).parents('tr').attr('data-id'),
                };
                $.ajax({
                    url:'/ads/ad/sort_order',
                    data:data,
                    type:'patch',

                })

            })



        })
    </script>
    <?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>